export default {

    //存储数据
    state: {
        isCollapse: false,
        currentMenu: null,
        tabsList: [
            {
                path: '/home',
                menuCode: 'home',
                menuName: '首页',
            }
        ]
    },
    //调用方法
    mutations: {
        collapseMenu(state) {
            state.isCollapse = !state.isCollapse
        },
        //选择标签 选择面包屑
        selectMenu(state, val) {
            if (val.path === '/home') {
                state.currentMenu = null
            } else {
                state.currentMenu = val
                //如果等于-1说明tabsList不存在那么插入，否则什么都不做
                let result = state.tabsList.findIndex(item => item.path === val.path)
                result === -1 ? state.tabsList.push(val) : ''

            }
            // val.name === 'home' ? (state.currentMenu = null) : (state.currentMenu = val)
        },
        //关闭标签
        closeTab(state, val) {
            //该方法的返回值：返回符合条件的第一个元素的下标
            let result = state.tabsList.findIndex(item => item.path === val.path)
            //第一个参数是起始下标，第二个参数是删除几个元素
            state.tabsList.splice(result, 1)

        },

        clearTabsList(state){
            state.tabsList=[ {
                path: '/home',
                menuCode: 'home',
                menuName: '首页',
            }];
        }

    },
    actions: {}


//删除起始下标为1，长度为1的一个值(len设置1，如果为0，则数组不变)
//var arr = ['a','b','c','d'];
//arr.splice(1,1);
//console.log(arr);
//['a','c','d'];

    //替换起始下标为1，长度为2的两个值为‘ttt’，len设置的1
   // var arr2 = ['a','b','c','d'];
   // arr2.splice(1,2,'ttt');
   // console.log(arr2);
//['a','ttt','d']
}
